package org.xx.armory.docs;

import static org.xx.armory.commons.Validators.notNull;

public final class ElementSize {
    private final float value;
    private final ElementSizeType type;

    public ElementSize(
            float value,
            ElementSizeType type
    ) {
        notNull(type, "type");

        this.value = value;
        this.type = type;
    }

    public final float getValue() {
        return this.value;
    }

    public final ElementSizeType getType() {
        return this.type;
    }

    public String toString() {
        switch (this.type) {
            case AUTO:
                return "auto";
            case PIXEL:
                return this.value + "px";
            case PERCENT:
                return this.value + "%";
            default:
                throw new IllegalStateException("unknown type: " + this.type);
        }
    }

    public enum ElementSizeType {
        /**
         * 自动
         */
        AUTO,

        /**
         * 像素
         */
        PIXEL,

        /**
         * 百分比
         */
        PERCENT
    }
}
